#include "CEUtilities.h"

#include "CECuboidPS.h"


//----------------------------------------------------------------------
CuboidPS::CuboidPS(const STRING &name,
				   const STRING &scriptsFile,
				   Object *father,
				   const Vector3 &offset,
				   const Radian &radianX, const Radian &radianY, const Radian &radianZ,
				   BOOL isVisible)
	: ParticleSystem(name,
					 scriptsFile,
					 father,
					 offset,
					 radianX, radianY, radianZ,
					 isVisible)
{
	m_EmitterType = PS_CUBOID;
	Init();
}


//----------------------------------------------------------------------
CuboidPS::~CuboidPS()
{
}


//----------------------------------------------------------------------
void CuboidPS::SetEmitBox(REAL halfWidth, REAL halfHeight, REAL halfDepth)
{
	m_fVarDirLength		= halfWidth;
	m_fVarRightLength	=  halfHeight;
	m_fVarUpLength		= halfDepth;
}


//----------------------------------------------------------------------
Vector3 CuboidPS::EmitFromSomeShape()
{
	return (GetRight() * RANDOM_NUM * m_fVarRightLength +
			GetUp()    * RANDOM_NUM * m_fVarUpLength    +
			GetDir()   * RANDOM_NUM * m_fVarDirLength);
}


//----------------------------------------------------------------------
void CuboidPS::SaveExternData(std::ofstream &fout) const
{
	fout << "<PS_Extra_Begin>" << endl;
	fout << "<Cuboid_Size> \t" << m_fVarRightLength << "\t" << m_fVarUpLength << "\t" << m_fVarDirLength << endl << endl;
	fout << "<PS_Extra_End>"   << endl;
}


//----------------------------------------------------------------------
void CuboidPS::LoadExternData(std::ifstream &fin)
{
	STRING str = CEUtil::GetNextStrNotComment(fin);
	while (str != "<PS_Extra_End>")
	{
		if (str == "<Cuboid_Size>")
		{
			m_fVarRightLength = CEUtil::StrToFloat(CEUtil::GetNextStrNotComment(fin));
			m_fVarUpLength	  = CEUtil::StrToFloat(CEUtil::GetNextStrNotComment(fin));
			m_fVarDirLength	  = CEUtil::StrToFloat(CEUtil::GetNextStrNotComment(fin));
		}
		else
		{
			str = CEUtil::GetThisLineRest(fin);
			continue;
		}
		str = CEUtil::GetNextStrNotComment(fin); 
   	}
}